package com.cn.http.interceptor;

import cn.com.allunion.sms.pojo.Smsrecord;
import com.cn.common.implement.CheckTypeImpl;
import com.cn.http.AbstractSmsrecordInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 联通短信拦截器，使用情景：指定发送的运营商标识不是auto，并且要求联通的电话号码全部通过联通的默认渠道发送
 * @author yang.jie
 * @email yang.jie@all-union.com.cn
 * @date 2016/5/5.
 * @copyright http://www.all-union.com.cn/
 */
public class UnicomSmsrecordInterceptor extends AbstractSmsrecordInterceptor {
    private static final Logger LOGGER = LoggerFactory.getLogger(UnicomSmsrecordInterceptor.class) ;

    private String joinNumMark;

    private CheckTypeImpl checkTypeImpl; ;

    @Override
    protected List<Smsrecord> preExecuteInternal(List<Smsrecord> smsrecordList) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("开始执行内部拦截方法，短信记录条数为： {}", smsrecordList.size());
        }

        List<Smsrecord> interceptedRecords = new ArrayList<>() ;
        for (Smsrecord sd : smsrecordList) {
            int result = checkTypeImpl.checkthePhone(sd.getSendNumber());
            if (10010 == result) { // 为联通号码
                interceptedRecords.add(sd);
            }
        }

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("内部拦截短信记录条数为： {}", interceptedRecords.size());
        }

        return interceptedRecords;
    }

    public CheckTypeImpl getCheckTypeImpl() {
        return checkTypeImpl;
    }

    public void setCheckTypeImpl(CheckTypeImpl checkTypeImpl) {
        this.checkTypeImpl = checkTypeImpl;
    }

    public String getJoinNumMark() {
        return joinNumMark;
    }

    public void setJoinNumMark(String joinNumMark) {
        this.joinNumMark = joinNumMark;
    }
}

